
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline seller-inline-3" style="width: 300px;">
                <input type="text" name="user_name" id="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                       class="layui-input" >
            </div>
        </div>
        <div class="layui-inline" style="padding-left: 5px;width: 150px;">
            <select name="type" >
                <option value="">全部</option>
                <option value="0">钱包</option>
                <option value="1">卡操作</option>
            </select>
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user_cash">查找钱包差异</button>
            </div>
        </div>
    </div>
    <div class="table-body">
        <table id="balanceTable" lay-filter="balanceTable"></table>
    </div>
</form>

<script>
    layui.use(['form', 'table'], function () {
        var tableIn = layui.table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            url: "{:url('userCashError')}",
            id: 'balanceTable',
            cols: [[
                { type: 'numbers'},
                { field: 'username', align: 'left', title: '用户' , width:200},
                { field: '', align: 'center', title: '错误类型' ,width:120,
                    templet: function (d) {
                        const type = d.type;
                        if(type == 0){
                            return '<font color="red">钱包</font>';
                        }else{
                            return '<font color="green">卡操作</font>';
                        }
                    }
                },
                { field: 'amount_error', align: 'right', style:'color:#FF5722;font-weight:bold' ,title: '记录金额' , width:150},
                { field: 'amount', align: 'right', title: '修正金额' , width:150 ,totalRow: true},
                { field: 'balance', align: 'right', title: '当时正确余额' , width:150 },
                { align: 'center', title: '错误时间',width:180,
                    templet: function (d) {
                        return layui.util.toDateString(d.time_error * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'desc', align: 'left', title: 'Desc' , width:250},
                { field: 'type_id', align: 'left', title: 'tableId' , width:100},
            ]],
            page: true,
            limit: 10000,
            limits: [10000],
        });

        layui.form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        layui.form.on('submit(user_cash)', function () {
            var loading =layer.load(1, {shade: [0.1,'#fff']});
            JsPost("{:url('xfUserCash')}",{username:$("#user_name").val()}, function(res){
                layer.close(loading);
                if(res.code >0){
                    $('#up_time').text(res.data.time);
                    layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                        tableIn.reload({
                            page:{
                                curr :1
                            }
                        });
                    });
                }else{
                    layer.msg(res.msg , {time:1500 , icon:2});
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>